package com.huangpeng.designmodel.singleton;

/**
 * @Author hp
 * @Title 饿汉式
 * @Package
 * @Date 2022/1/19 9:51
 * @Description
 * @Version 1.0
 */
public class HungryMan {
    //私有的构造方法
    public HungryMan() {
    }
    //私有的静态变量
    private final static HungryMan hungryMan;
    //静态代码块
    static {
        hungryMan = new HungryMan();
    }
    //对外的公有方法
    public static HungryMan getInstance(){
        return hungryMan;
    }

    public static void main(String[] args){
        HungryMan a1=HungryMan.getInstance();
        System.out.println(a1.hashCode());
        HungryMan a2=HungryMan.getInstance();
        System.out.println(a2.hashCode());
    }


}
